package com.jichangxiu.framework.entity.bo;

import lombok.Getter;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.io.Serializable;
import java.util.Collection;

public class SecurityToken extends AbstractAuthenticationToken implements Serializable {

    private static final long serialVersionUID = 1L;

    @Getter
    private Object tenantId;

    private final Object principal;

    private Object credentials;

    public SecurityToken(Object tenantId, Object principal, Object credentials) {
        super(null);
        this.tenantId = tenantId;
        this.principal = principal;
        this.credentials = credentials;
        this.setAuthenticated(false);
    }

    public SecurityToken(Object tenantId, Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.tenantId = tenantId;
        this.principal = principal;
        this.credentials = credentials;
        super.setAuthenticated(true);
    }

    @Override
    public void setAuthenticated(boolean authenticated) throws IllegalArgumentException {
        super.setAuthenticated(authenticated);
    }

    @Override
    public void eraseCredentials() {
        super.eraseCredentials();
        this.credentials = null;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }

    @Override
    public Object getCredentials() {
        return this.credentials;
    }

}
